	function SharePointValidator() {
		this.Required = [];
		this.PhoneNumbers = [];
		this.ZipCodes = [];
		this.EmailAddresses = [];
		this.ErrorColor = "990000";
	}
		
	SharePointValidator.prototype.addRequired = function(name) {
		this.Required.push(name);
	}
	
	SharePointValidator.prototype.addPhoneNumber = function(name) {
		this.Required.push(name);
		this.PhoneNumbers.push(name);
	}
	
	SharePointValidator.prototype.addZipCode = function(name) {
		this.Required.push(name);
		this.ZipCodes.push(name);
	}
	
	SharePointValidator.prototype.addEmailAddress = function(name) {
		this.Required.push(name);
		this.EmailAddresses.push(name);
	}
	
	SharePointValidator.prototype.validateRegex = function(myArray, regex, errorMessage) {
		var errorColor = this.ErrorColor;
		
		jQuery.each(myArray, function(index, value) {
			$("input[title='" + value + "']").each(function() {
				var myResult = $(this).filter(function() { return $(this).attr("value").match(regex); });
				
				$("div", $(this).parent()).remove();
				if (myResult.val()) {
					isValid = isValid && true;
					$(this).css("background-color", "");
				} else {
					isValid = false;
					$('<div style="color: #' + errorColor + ';">' + errorMessage + '.</div>').appendTo($(this).parent());
					$(this).css("background-color", errorColor);
				}
			});
		});
	}
	
	SharePointValidator.prototype.validate = function() {
		var isValid = true;
		var errorColor = this.ErrorColor;
		
		jQuery.each(this.Required, function(index, value) {
			$("input[title='" + value + "']").each(function() {
				$("span.ms-formvalidation", $(this).parent()).remove();
			});
		});
		
		jQuery.each(this.Required, function(index, value) {
			$("input[title='" + value + "']").each(function() {
				var fieldId = "spValidator" + value.replace(' ', '');
				var field = $(this);
				var fieldValue = field.attr("value");
				
				if (fieldValue.length <= 0) {
					isValid = false;
					if ($("#" + fieldId).length <= 0) {
						$('<div style="color: #' + errorColor + ';" id="' + fieldId + '">Please enter a value for ' + value + '.</div>').appendTo(field.parent());
						field.css("background-color", errorColor);
					}
				} else {
					if ($("#" + fieldId).length > 0) {
						$("#" + fieldId).hide("slow", function() {
							$(this).remove();
						});
					}
					isValid = isValid && true;
					field.css("background-color", "");
				}
			});
		});
		
		this.validateRegex(this.PhoneNumbers, /^[2-9]\d{2}-\d{3}-\d{4}$/, "Please enter a valid phone number.");	
		this.validateRegex(this.ZipCodes, /^\d{5}$/, "Please enter a valid Zip Code.");
		this.validateRegex(this.EmailAddresses, /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/, "Please enter a valid Email Address.");
		
		if (!isValid) {
			$("input[value='OK']").attr("disabled", "true");
		} else {
			$("input[value='OK']").attr("disabled", "");
		}
	}